package com.lj.sys.param;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.text.StrPool;
import com.lj.sys.entity.SysDataScope;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import jakarta.validation.constraints.NotBlank;
import com.lj.sys.enums.SysDataScopeType;
import com.lj.common.utils.EnumUtils;

import java.util.List;

/**
 * <p>
 * 数据范围表 保存参数
 * </p>
 *
 * @author lj
 * @since 2025-08-06 18:24:15
 */
@Data
@Schema(description = "数据范围表 保存参数")
public class SysDataScopeSaveParam {

    @Schema(description = "请求的接口路径")
    @NotBlank(message = "请求的接口路径 不能为空")
    private String urlPath;

    @Schema(description = "目标id(用户id或者角色id)")
    @NotNull(message = "目标id不能为空 不能为空")
    private Long targetId;

    @Schema(description = "数据范围 参考字典: SysDataScopeType")
    @NotNull(message = "数据范围 不能为空")
    private Integer scope;

    @Schema(description = "自定义范围(部门id多个逗号分隔)")
    private List<String> custom;

    public SysDataScope toEntity() {
        SysDataScope entity = new SysDataScope();
        entity.setUrlPath(urlPath);
        entity.setTargetId(targetId);
        entity.setScope(EnumUtils.getByValue(SysDataScopeType.class, scope));
        entity.setCustom(CollUtil.join(custom, StrPool.COMMA));
        return entity;
    }
}
